<script setup lang="ts">
import Title from './Title.vue';
import { ref, onMounted } from 'vue';
import { init } from '../echarts-utils';
import type { ECOption } from '../echarts-utils';

const chart = ref<HTMLElement>();

function initChart() {
  const myChart = init(chart.value);
  myChart.setOption({
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 0,
      top: 10,
      icon: 'circle',
      textStyle: {
        color: '#fff'
      }
    },
    series: [
      {
        name: '年龄比例',
        type: 'pie',
        radius: ['14%', '70%'],
        center: ['50%', '50%'],
        roseType: 'area',
        right: -40,
        labelLine: {
          show: true
        },
        data: [
          { value: 20, name: '云南' },
          { value: 26, name: '北京' },
          { value: 24, name: '山东' },
          { value: 25, name: '河北' },
          { value: 20, name: '江苏' },
          { value: 25, name: '浙江' },
          { value: 30, name: '四川' },
          { value: 42, name: '湖北' }
        ]
      }
    ]
  } as ECOption);
}

onMounted(() => {
  initChart();
});
</script>

<template>
  <div class="area fit column">
    <Title title="地区分布"></Title>
    <div ref="chart" class="chart col"></div>
  </div>
</template>

<style scoped lang="scss">
.area {
  background: url(../images/dataScreen-main-rb.png) no-repeat;
}
</style>
